package org.lds.message.center.helloworld.autoconfigure;

import lombok.RequiredArgsConstructor;
import org.lds.message.center.helloworld.HelloWorldHandler;
import org.lds.message.center.helloworld.HelloWorldMessageService;
import org.lds.message.center.helloworld.constant.HelloWorldConstant;
import org.lds.message.center.helloworld.consumer.HelloWorldConsumer;
import org.lds.message.center.helloworld.health.endpoint.HelloWorldHealthEndpoint;
import org.lds.message.center.helloworld.properties.HelloWorldProperties;
import org.lds.message.center.helloworld.starter.HelloWorldRegisterAdmin;
import org.lds.message.center.plugin.core.kafka.KafkaProducer;
import org.lds.message.center.plugin.core.remote.RemoteService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = HelloWorldConstant.HELLO_WORLD_PREFIX, name = "enabled", havingValue = "true")
@EnableConfigurationProperties({HelloWorldProperties.class})
public class HelloWorldAutoConfiguration {
    private final HelloWorldProperties helloWorldProperties;

    @Bean
    public HelloWorldMessageService helloWorldMessageService(KafkaProducer kafkaProducer, HelloWorldHandler helloWorldHandler) {
        return new HelloWorldMessageService(helloWorldHandler, helloWorldProperties, kafkaProducer);
    }

    @Bean
    public HelloWorldHandler helloWorldHandler() {
        return new HelloWorldHandler();
    }

    @Bean
    public HelloWorldConsumer helloWorldConsumer(HelloWorldMessageService helloWorldMessageService) {
        return new HelloWorldConsumer(helloWorldMessageService);
    }

    @Bean
    public HelloWorldRegisterAdmin helloWorldRegisterAdmin(RemoteService remoteService) {
        return new HelloWorldRegisterAdmin(remoteService);
    }

    @Bean
    public HelloWorldHealthEndpoint helloWorldHealthEndpoint() {
        return new HelloWorldHealthEndpoint();
    }

}
